/**
  ******************************************************************************
  * @file    stm8l15x_i2c.h
  * @author  MCD Application Team
  * @version V1.1.0-RC2
  * @date    03/11/2010
  * @brief   This file contains all the functions prototypes for the I2C firmware 
  *          library.
  ******************************************************************************
  * @copy
  *
  * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  *
  * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM8L15x_I2C_H
#define __STM8L15x_I2C_H

/* Includes ------------------------------------------------------------------*/
#include "stm8l15x.h"

/** @addtogroup STM8L15x_StdPeriph_Driver
  * @{
  */
  
/* Exported variables ------------------------------------------------------- */
/* Exported types ------------------------------------------------------------*/

/** @addtogroup I2C_Exported_Types
  * @{
  */

/**
  * @brief I2C mode
  */
typedef enum
{
  I2C_Mode_I2C           = (uint8_t)0x00,   /*!< I2C mode */
  I2C_Mode_SMBusDevice   = (uint8_t)0x02,   /*!< SMBus Device mode */
  I2C_Mode_SMBusHost     = (uint8_t)0x0A     /*!< SMBus Host mode */
} I2C_Mode_TypeDef;  

/**
  * @brief I2C duty cycle (fast mode only)
  */
typedef enum
{
    I2C_DutyCycle_2    = (uint8_t)0x00,  /*!< Fast mode Tlow/THigh = 2 */
    I2C_DutyCycle_16_9 = (uint8_t)0x40   /*!< Fast mode Tlow/Thigh = 16/9 */
} I2C_DutyCycle_TypeDef;


/**
  * @brief I2C Acknowledgement configuration
  */
typedef enum
{
    I2C_Ack_Disable = (uint8_t)0x00,  /*!< No acknowledge */
    I2C_Ack_Enable  = (uint8_t)0x04   /*!< Acknowledge Enabled */
} I2C_Ack_TypeDef;

/**
  * @brief I2C Acknowledgement position configuration
  */
typedef enum
{
    I2C_AckPosition_Current = (uint8_t)0x00,   /*!< Acknowledge on the current byte */
    I2C_AckPosition_Next    = (uint8_t)0x08    /*!< Acknowledge on the next byte */
} I2C_AckPosition_TypeDef;

/**
  * @brief I2C Addressing Mode (slave mode only)
  */
typedef enum
{
    I2C_AcknowledgedAddress_7bit  = (uint8_t)0x00,  /*!< 7-bit slave address (10-bit address not acknowledged) */
    I2C_AcknowledgedAddress_10bit = (uint8_t)0x80   /*!< 10-bit slave address (7-bit address not acknowledged) */
} I2C_AcknowledgedAddress_TypeDef;

/**
  * @brief I2C transfer direction
  * Warning: the values correspond to the ADD0 bit position in the OARL register
  */
typedef enum
{
    I2C_Direction_Transmitter = (uint8_t)0x00,  /*!< Transmission direction */
    I2C_Direction_Receiver    = (uint8_t)0x01   /*!< Reception direction */
} I2C_Direction_TypeDef;

/**
  * @brief I2C SMBus Alert pin configuration
  */
typedef enum
{
  I2C_SMBusAlert_High = (uint8_t)0x00,  /*!< SMBAlert pin high */
  I2C_SMBusAlert_Low  =  (uint8_t)0x01   /*!< SMBAlert pin Low */
} I2C_SMBusAlert_TypeDef;

/**
  * @brief I2C PEC position
  */
typedef enum
{
  I2C_PECPosition_Current = (uint8_t)0x00,  /*!< Current byte in shift register is PEC */
  I2C_PECPosition_Next    = (uint8_t)0x08   /*!< Next  byte in shift register is PEC */
} I2C_PECPosition_TypeDef;

/**
  * @brief I2C Flags
  * Elements values convention: 0xXY
  *  X = SRx registers index
  *      X = 1 : SR1
  *      X = 2 : SR2
  *      X = 3 : SR3
  *  Y = Flag position in the register 
  */

typedef enum
{
    /* SR1 register flags */
    I2C_FLAG_TXE        = (uint16_t)0x0180,  /*!< Transmit Data Register Empty flag */
    I2C_FLAG_RXNE       = (uint16_t)0x0140,  /*!< Read Data Register Not Empty flag */
    I2C_FLAG_STOPF      = (uint16_t)0x0110,  /*!< Stop detected flag */
    I2C_FLAG_ADD10      = (uint16_t)0x0108,  /*!< 10-bit Header sent flag */
    I2C_FLAG_BTF        = (uint16_t)0x0104,  /*!< Data Byte Transfer Finished flag */
    I2C_FLAG_ADDR       = (uint16_t)0x0102,  /*!< Address Sent/Matched (master/slave) flag */
    I2C_FLAG_SB         = (uint16_t)0x0101,  /*!< Start bit sent flag */

    /* SR2 register flags */
    I2C_FLAG_SMBALERT   = (uint16_t)0x0280,  /*!< SMBUS Alert flag */
    I2C_FLAG_TIMEOUT     = (uint16_t)0x0240,  /*!< Time out flag */  
    I2C_FLAG_WUFH       = (uint16_t)0x0220,  /*!< Wake Up From Halt flag */
    I2C_FLAG_PECERR     = (uint16_t)0x0210,  /*!< PEC error flag */    
    I2C_FLAG_OVR        = (uint16_t)0x0208,  /*!< Overrun/Underrun flag */
    I2C_FLAG_AF         = (uint16_t)0x0204,  /*!< Acknowledge Failure flag */
    I2C_FLAG_ARLO       = (uint16_t)0x0202,  /*!< Arbitration Loss flag */
    I2C_FLAG_BERR       = (uint16_t)0x0201,  /*!< Misplaced Start or Stop condition */

    /* SR3 register flags */
		I2C_FLAG_DUALF    = (uint16_t)0x0380,  /*!< DUAL Flag */
    I2C_FLAG_SMBHOST    = (uint16_t)0x0340,  /*!< SMBUS host Flag */
    I2C_FLAG_SMBDEFAULT = (uint16_t)0x0320,  /*!< SMBUS default flag */  
    I2C_FLAG_GENCALL    = (uint16_t)0x0310,  /*!< General Call header received Flag */
    I2C_FLAG_TRA        = (uint16_t)0x0304,  /*!< Transmitter Receiver flag */
    I2C_FLAG_BUSY       = (uint16_t)0x0302,  /*!< Bus Busy flag */
    I2C_FLAG_MSL        = (uint16_t)0x0301   /*!< Master Slave flag */
} I2C_FLAG_TypeDef;


/**
  * @brief I2C Pending bits
  * Elements values convention: 0xXYZZ
  *  X = SRx registers index
  *      X = 0 : ITR
  *      X = 1 : SR1
  *      X = 2 : SR2
  *  Y = Position of the corresponding Interrupt
  *  ZZ = flag mask in the dedicated register(X register)
  */

typedef enum
{
    I2C_IT_ERR             = (uint16_t)0x0001,   /*!< Error Interruption */
    I2C_IT_EVT             = (uint16_t)0x0002,   /*!< Event Interruption */
    I2C_IT_BUF             = (uint16_t)0x0004,   /*!< Buffer Interruption */
    /* SR1 register*/
    I2C_IT_TXE             = (uint16_t)0x1680,   /*!< Transmit Data Register Empty  */
    I2C_IT_RXNE            = (uint16_t)0x1640,   /*!< Read Data Register Not Empty  */
    I2C_IT_STOPF           = (uint16_t)0x1210,   /*!< Stop detected  */
    I2C_IT_ADD10           = (uint16_t)0x1208,   /*!< 10-bit Header sent */
    I2C_IT_BTF             = (uint16_t)0x1204,   /*!< Data Byte Transfer Finished  */
    I2C_IT_ADDR            = (uint16_t)0x1202,   /*!< Address Sent/Matched (master/slave)  */
    I2C_IT_SB              = (uint16_t)0x1201,   /*!< Start bit sent  */

    /* SR2 register*/
    I2C_IT_SMBALERT        = (uint16_t)0x2280,   /*!< SMBUS alert  */
    I2C_IT_TIMEOUT         = (uint16_t)0x2240,   /*!< Time out  */    
    I2C_IT_WUFH            = (uint16_t)0x2220,   /*!< PEC error  */
    I2C_IT_PECERR          = (uint16_t)0x2210,   /*!< Wake Up From Halt  */
    I2C_IT_OVR             = (uint16_t)0x2108,   /*!< Overrun/Underrun  */
    I2C_IT_AF              = (uint16_t)0x2104,   /*!< Acknowledge Failure  */
    I2C_IT_ARLO            = (uint16_t)0x2102,   /*!< Arbitration Loss  */
    I2C_IT_BERR            = (uint16_t)0x2101    /*!< Misplaced Start or Stop condition */
} I2C_IT_TypeDef;

/**
  * @brief I2C possible events
  * Values convention: 0xXXYY
  * XX = Event SR3 corresponding value
  * YY = Event SR1 corresponding value
  * @note if Event = EV3_2 the rule above does not apply
  * YY = Event SR2 corresponding value
  */
typedef enum
{
    I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED       = (uint16_t)0x0682,  /*!< EV1: TRA, BUSY, TXE and ADDR flags */
    I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED          = (uint16_t)0x0202,  /*!< EV1: BUSY and ADDR flags */
	  I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED = (uint16_t)0x8680,  /*! EV1: DUALF, TRA, BUSY and TXE flags */	
	  I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED    = (uint16_t)0x8200,  /*! DUALF and BUSY flags */
		I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED        = (uint16_t)0x1200,  /*! GENCALL and BUSY flags */
    I2C_EVENT_SLAVE_BYTE_RECEIVED                     = (uint16_t)0x0240,  /*!< EV2: BUSY and RXNE flags */
    I2C_EVENT_SLAVE_BYTE_TRANSMITTED                  = (uint16_t)0x0684,  /*!< EV3: TRA, BUSY, TXE and BTF flags */
    I2C_EVENT_SLAVE_STOP_DETECTED                     = (uint16_t)0x0010,  /*!< EV4: STOPF flag */
    I2C_EVENT_SLAVE_ACK_FAILURE                       = (uint16_t)0x0004,  /*!< EV3_2: AF flag */
    
    I2C_EVENT_MASTER_MODE_SELECT                      = (uint16_t)0x0301,  /*!< EV5: BUSY, MSL and SB flag */
    I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED        = (uint16_t)0x0782,  /*!< EV6: BUSY, MSL, ADDR, TXE and TRA flags*/
    I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED           = (uint16_t)0x0302,  /*!< EV6: BUSY, MSL and ADDR flags */
    I2C_EVENT_MASTER_BYTE_RECEIVED                    = (uint16_t)0x0340,  /*!< EV7: BUSY, MSL and RXNE flags */
    I2C_EVENT_MASTER_BYTE_TRANSMITTING                = (uint16_t)0x0780,  /*!< EV8: TRA, BUSY, MSL, TXE flags */
    I2C_EVENT_MASTER_BYTE_TRANSMITTED                 = (uint16_t)0x0784,  /*!< EV8_2: TRA, BUSY, MSL, TXE and BTF flags */
    I2C_EVENT_MASTER_MODE_ADDRESS10                   = (uint16_t)0x0308   /*!< EV9: BUSY, MSL and ADD10 flags */
} I2C_Event_TypeDef;


/**
  * @brief I2C registers
  */
typedef enum
{
  I2C_Register_CR1    = (uint8_t)0x00,   /*!< Control register 1 */
  I2C_Register_CR2    = (uint8_t)0x01,   /*!< Control register 2 */
  I2C_Register_FREQR  = (uint8_t)0x02,   /*!< Frequency register */
  I2C_Register_OARL   = (uint8_t)0x03,   /*!< Own address register LSB */
  I2C_Register_OARH   = (uint8_t)0x04,   /*!< Own address register MSB */
  I2C_Register_DR     = (uint8_t)0x06,   /*!< Data register */
  I2C_Register_SR1    = (uint8_t)0x07,   /*!< Status register 1 */
  I2C_Register_SR2    = (uint8_t)0x08,   /*!< Status register 2 */
  I2C_Register_SR3    = (uint8_t)0x09,   /*!< Status register 3 */
  I2C_Register_ITR    = (uint8_t)0x0A,   /*!< Interrupt and DMA register */
  I2C_Register_CCRL   = (uint8_t)0x0B,   /*!< Clock control register low */
  I2C_Register_CCRH   = (uint8_t)0x0C,   /*!< Clock control register high */
  I2C_Register_TRISER = (uint8_t)0x0D,   /*!< TRISE register */
  I2C_Register_PECR   = (uint8_t)0x0E    /*!< PEC register */
} I2C_Register_TypeDef;


/**
  * @}
  */

/* Exported constants --------------------------------------------------------*/
/** @addtogroup I2C_Exported_Constants
  * @{
  */
#define I2C_MAX_STANDARD_FREQ ((uint32_t)100000)
#define I2C_MAX_FAST_FREQ     ((uint32_t)400000)

/**
  *@}
  */

/* Exported macros -----------------------------------------------------------*/
/* Private macros ------------------------------------------------------------*/

/** @addtogroup I2C_Private_Macros
  * @{
  */

/**
  * @brief Macro used by the assert function to check the different functions parameters.
  */

/**
  * @brief  Macro used by the assert function to check the different I2C modes.
  */
#define IS_I2C_MODE(MODE)(((MODE) == I2C_Mode_I2C) || \
                          ((MODE) == I2C_Mode_SMBusDevice) || \
                          ((MODE) == I2C_Mode_SMBusHost)) 
 
/**
  * @brief  Macro used by the assert function to check the different I2C duty cycles.
  */
#define IS_I2C_DUTY_CYCLE(CYCLE)(((CYCLE) == I2C_DutyCycle_2) || \
                                 ((CYCLE) == I2C_DutyCycle_16_9))

/**
  * @brief  Macro used by the assert function to check the different acknowledgement configuration
  */
#define IS_I2C_ACK_STATE(STATE) (((STATE) == I2C_Ack_Disable) || \
                                 ((STATE) == I2C_Ack_Enable))
/**
  * @brief  Macro used by the assert function to check the different acknowledgement position
  */
#define IS_I2C_ACK_POSITION(POSITION) (((POSITION) == I2C_AckPosition_Next) || \
                                       ((POSITION) == I2C_AckPosition_Current))

/**
  * @brief  Macro used by the assert function to check the different I2C PEC positions.
  */
#define IS_I2C_PEC_POSITION(POSITION) (((POSITION) == I2C_PECPosition_Current) || \
                                       ((POSITION) == I2C_PECPosition_Next))

/**
  * @brief  Macro used by the assert function to check the different I2C addressing modes.
  */
#define IS_I2C_ACKNOWLEDGE_ADDRESS(ADDMODE) (((ADDMODE) == I2C_AcknowledgedAddress_7bit) || \
                                             ((ADDMODE) == I2C_AcknowledgedAddress_10bit))

/**
  * @brief  Macro used by the assert function to check the different I2C SMBus Alert pin configuartion.
  */
#define IS_I2C_SMBUS_ALERT(ALERT) (((ALERT) == I2C_SMBusAlert_High) || \
                                   ((ALERT) == I2C_SMBusAlert_Low))

/**
  * @brief  Macro used by the assert function to check the different I2C communcation direction.
  */
#define IS_I2C_DIRECTION(DIR)(((DIR) == I2C_Direction_Transmitter) || \
                              ((DIR) == I2C_Direction_Receiver ))

/**
  * @brief  Macro used by the assert function to check the different I2C flags.
  */
#define IS_I2C_GET_FLAG(FLAG) (((FLAG) == I2C_FLAG_TXE)        || \
                               ((FLAG) == I2C_FLAG_RXNE)       || \
                               ((FLAG) == I2C_FLAG_STOPF)      || \
                               ((FLAG) == I2C_FLAG_ADD10)      || \
                               ((FLAG) == I2C_FLAG_BTF)        || \
                               ((FLAG) == I2C_FLAG_ADDR)       || \
                               ((FLAG) == I2C_FLAG_SB)         || \
                               ((FLAG) == I2C_FLAG_SMBALERT)   || \
                               ((FLAG) == I2C_FLAG_TIMEOUT)    || \
                               ((FLAG) == I2C_FLAG_WUFH)       || \
                               ((FLAG) == I2C_FLAG_PECERR)     || \
                               ((FLAG) == I2C_FLAG_OVR)        || \
                               ((FLAG) == I2C_FLAG_AF)         || \
                               ((FLAG) == I2C_FLAG_ARLO)       || \
                               ((FLAG) == I2C_FLAG_BERR)       || \
															 ((FLAG) == I2C_FLAG_DUALF)      || \
                               ((FLAG) == I2C_FLAG_SMBHOST)    || \
                               ((FLAG) == I2C_FLAG_SMBDEFAULT) || \
                               ((FLAG) == I2C_FLAG_GENCALL)    || \
                               ((FLAG) == I2C_FLAG_TRA)        || \
                               ((FLAG) == I2C_FLAG_BUSY)       || \
                               ((FLAG) == I2C_FLAG_MSL))

/**
  * @brief  Macro used by the assert function to check the I2C flags to clear.
  */
#define IS_I2C_CLEAR_FLAG(FLAG) ((((FLAG) & (uint16_t)0xFD00) == (uint16_t)0x00) && ((FLAG) != (uint16_t)0x00))

/**
  * @brief Macro used by the assert_param function in order to check the different
  *  sensitivity values for the Interrupts
  */
#define IS_I2C_CONFIG_IT(IT) ((((IT) & (uint16_t)0xFFF8) == 0x00) && ((IT) != (uint16_t)0x00))

/**
  * @brief  Macro used by the assert function to check the different I2C possible
  *   pending bits to clear by writing 0.
  */
#define IS_I2C_CLEAR_IT(IT) ((((IT) & (uint16_t)0xDC00) == (uint16_t)0x00) && ((IT) != (uint16_t)0x00))

/**
  * @brief  Macro used by the assert function to check the different I2C possible pending bits.
  */
#define IS_I2C_GET_IT(IT) (((IT) == I2C_IT_OVR)      ||\
                           ((IT) == I2C_IT_AF)       ||\
                           ((IT) == I2C_IT_ARLO)     ||\
                           ((IT) == I2C_IT_BERR)     ||\
                           ((IT) == I2C_IT_TXE)      ||\
                           ((IT) == I2C_IT_RXNE)     ||\
                           ((IT) == I2C_IT_STOPF)    ||\
                           ((IT) == I2C_IT_ADD10)    ||\
                           ((IT) == I2C_IT_BTF)      ||\
                           ((IT) == I2C_IT_ADDR)     ||\
                           ((IT) == I2C_IT_PECERR)   ||\
                           ((IT) == I2C_IT_TIMEOUT)  ||\
                           ((IT) == I2C_IT_SMBALERT) ||\
                           ((IT) == I2C_IT_WUFH)     ||\
                           ((IT) == I2C_IT_SB))
/**
  * @brief  Macro used by the assert function to check the different I2C possible events.
  */
#define IS_I2C_EVENT(EVENT) (((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_ADDRESS_MATCHED) || \
                             ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_ADDRESS_MATCHED) || \
                             ((EVENT) == I2C_EVENT_SLAVE_TRANSMITTER_SECONDADDRESS_MATCHED) || \
                             ((EVENT) == I2C_EVENT_SLAVE_RECEIVER_SECONDADDRESS_MATCHED) || \
                             ((EVENT) == I2C_EVENT_SLAVE_GENERALCALLADDRESS_MATCHED) || \
                             ((EVENT) == I2C_EVENT_SLAVE_BYTE_RECEIVED) || \
                             ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_DUALF)) || \
                             ((EVENT) == (I2C_EVENT_SLAVE_BYTE_RECEIVED | I2C_FLAG_GENCALL)) || \
                             ((EVENT) == I2C_EVENT_SLAVE_BYTE_TRANSMITTED) || \
                             ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_DUALF)) || \
                             ((EVENT) == (I2C_EVENT_SLAVE_BYTE_TRANSMITTED | I2C_FLAG_GENCALL)) || \
                             ((EVENT) == I2C_EVENT_SLAVE_ACK_FAILURE) || \
                             ((EVENT) == I2C_EVENT_SLAVE_STOP_DETECTED) || \
                             ((EVENT) == I2C_EVENT_MASTER_MODE_SELECT) || \
                             ((EVENT) == I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) || \
                             ((EVENT) == I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) || \
                             ((EVENT) == I2C_EVENT_MASTER_BYTE_RECEIVED) || \
                             ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTED) || \
                             ((EVENT) == I2C_EVENT_MASTER_BYTE_TRANSMITTING) || \
                             ((EVENT) == I2C_EVENT_MASTER_MODE_ADDRESS10))
/**
  * @brief  Macro used by the assert function to check the different I2C registers.
  */
#define IS_I2C_REGISTER(REGISTER) (((REGISTER) == I2C_Register_CR1) || \
                                   ((REGISTER) == I2C_Register_CR2) || \
                                   ((REGISTER) == I2C_Register_FREQR) || \
                                   ((REGISTER) == I2C_Register_OARL) || \
                                   ((REGISTER) == I2C_Register_OARH) || \
                                   ((REGISTER) == I2C_Register_DR) || \
                                   ((REGISTER) == I2C_Register_SR1) || \
                                   ((REGISTER) == I2C_Register_SR2) || \
                                   ((REGISTER) == I2C_Register_SR3) || \
                                   ((REGISTER) == I2C_Register_ITR) || \
                                   ((REGISTER) == I2C_Register_CCRL) || \
                                   ((REGISTER) == I2C_Register_CCRH) || \
                                   ((REGISTER) == I2C_Register_TRISER) || \
                                   ((REGISTER) == I2C_Register_PECR))
/**
  * @brief  Macro used by the assert function to check the different I2C possible own address.
  */
#define IS_I2C_OWN_ADDRESS(ADDRESS) ((ADDRESS) <= (uint16_t)0x03FF)

/**
  * @brief  Macro used by the assert function to check the different I2C address
  * The address must be even 
  */
#define IS_I2C_ADDRESS(ADD) (((ADD) & (uint8_t)0x01) == (uint8_t)0x00)

/**
  * @brief  Macro used by the assert function to check that I2C Output clock frequency must be between 1Hz and 400kHz.
  */
#define IS_I2C_OUTPUT_CLOCK_FREQ(FREQ) (((FREQ) >= (uint8_t)1) && ((FREQ) <= I2C_MAX_FAST_FREQ))

/**
  * @}
  */

/* Exported functions ------------------------------------------------------- */
/** @addtogroup I2C_Exported_Functions
  * @{
  */

void I2C_DeInit(I2C_TypeDef* I2Cx);
void I2C_Init(I2C_TypeDef* I2Cx, uint32_t OutputClockFrequency, uint16_t OwnAddress,
              I2C_Mode_TypeDef I2C_Mode, I2C_DutyCycle_TypeDef I2C_DutyCycle,
              I2C_Ack_TypeDef I2C_Ack, I2C_AcknowledgedAddress_TypeDef I2C_AcknowledgedAddress);
void I2C_Cmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_ITConfig(I2C_TypeDef* I2Cx, I2C_IT_TypeDef I2C_IT, FunctionalState NewState);
void I2C_DMACmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_DMALastTransferCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_GeneralCallCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_GenerateSTART(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_GenerateSTOP(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_SoftwareResetCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_StretchClockCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_ARPCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_AcknowledgeConfig(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_OwnAddress2Config(I2C_TypeDef* I2Cx, uint8_t Address);
void I2C_DualAddressCmd(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_AckPositionConfig(I2C_TypeDef* I2Cx, I2C_AckPosition_TypeDef I2C_AckPosition);
void I2C_FastModeDutyCycleConfig(I2C_TypeDef* I2Cx, I2C_DutyCycle_TypeDef I2C_DutyCycle);
void I2C_SMBusAlertConfig(I2C_TypeDef* I2Cx, I2C_SMBusAlert_TypeDef I2C_SMBusAlert);
void I2C_PECPositionConfig(I2C_TypeDef* I2Cx, I2C_PECPosition_TypeDef I2C_PECPosition);
void I2C_TransmitPEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
void I2C_CalculatePEC(I2C_TypeDef* I2Cx, FunctionalState NewState);
ErrorStatus I2C_CheckEvent(I2C_TypeDef* I2Cx, I2C_Event_TypeDef I2C_Event);
I2C_Event_TypeDef I2C_GetLastEvent(I2C_TypeDef* I2Cx);
uint8_t I2C_ReceiveData(I2C_TypeDef* I2Cx);
void I2C_Send7bitAddress(I2C_TypeDef* I2Cx, uint8_t Address, I2C_Direction_TypeDef I2C_Direction);
void I2C_SendData(I2C_TypeDef* I2Cx, uint8_t Data);
uint8_t I2C_GetPEC(I2C_TypeDef* I2Cx);
uint8_t I2C_ReadRegister(I2C_TypeDef* I2Cx, I2C_Register_TypeDef I2C_Register);
FlagStatus I2C_GetFlagStatus(I2C_TypeDef* I2Cx, I2C_FLAG_TypeDef I2C_FLAG);
void I2C_ClearFlag(I2C_TypeDef* I2Cx, I2C_FLAG_TypeDef I2C_FLAG);
ITStatus I2C_GetITStatus(I2C_TypeDef* I2Cx, I2C_IT_TypeDef I2C_IT);
void I2C_ClearITPendingBit(I2C_TypeDef* I2Cx, I2C_IT_TypeDef I2C_IT);

/**
  * @}
  */

#endif /* __STM8L15x_I2C_H */

/**
  * @}
  */
    
/******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
